//
//  UIImageView+WCAWebCache.m
//  WeChatAssistant
//
//  Created by Guo Rui on 2017/11/24.
//  Copyright © 2017年 GR Harry. All rights reserved.
//

#import "UIImageView+WCAWebCache.h"
#import "WCAImageDownloader.h"

@implementation UIImageView (WCAWebCache)

- (void)setImageURL:(NSString *)url placeholder:(UIImage *)placeholder
{
    if (placeholder) {
        self.image = placeholder;
    }
    
    __weak UIImageView *weakself = self;
    [WCAImageDownloader.sharedInstance cacelWithURL:url];
    [WCAImageDownloader.sharedInstance downloadWithURL:url completionBlock:^(UIImage *image, NSError *error) {
        if (!error) {
            dispatch_sync(dispatch_get_main_queue(), ^{
                weakself.image = image;
            });
        }
    }];
}

@end
